#ifndef _CONNECTION_H
#define _CONNECTION_H

#include <memory>
#include <boost/asio.hpp>
#include <sstream>
#include "Packet.h"
#include "Notifier.hpp"

class Connection : public std::enable_shared_from_this<Connection> {
public:
    boost::asio::ip::tcp::socket socket;
    std::vector<char> read_buffer;
    Notifier notifier;
    static std::shared_ptr<Connection> create(boost::asio::io_context& io_context, boost::asio::ip::tcp::resolver::results_type);

    /**
     * @param packet
     */
    void asyncSend(const Packet& packet);

    void asyncReceive();

    void close(){
        if (socket.is_open())
            socket.close();
    };

    Connection(boost::asio::io_context& io_context, boost::asio::ip::tcp::resolver::results_type results_type);
private:
};
#endif //_CONNECTION_H